import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '../views/Login.vue'
import Main from '../views/Main.vue'
import Welcome from '../views/Welcome.vue'
import Roles from '../components/Roles.vue'
import User from '../components/User.vue'
import PersonalCenter from '../components/PersonalCenter.vue'
import ShopTable from '../components/ShopTable.vue'
import Warehouse from '../components/Warehouse.vue'
import GoodsProp from '../components/GoodsProp.vue'
import GoodsPropgroup from '../components/GoodsPropgroup.vue'
import Distributor from '../components/Distributor.vue'
import Brand from '../components/Brand.vue'
import GoodsGeneral from '../components/GoodsGeneral.vue'
import GoodsSmall from '../components/GoodsSmall.vue'
import GoodsSmaller from '../components/GoodsSmaller.vue'
import Commodity from '../components/Commodity.vue'
import About from '../views/About.vue'
Vue.use(VueRouter)

const routes = [{
		path: '/about',
		name: 'About',
		component: About
	}, {
		path: '/',
		name: 'Login',
		component: Login
	},
	{
		path: '/main',
		name: 'Main',
		component: Main,
		children: [{
				path: '/main/Welcome',
				name: 'Welcome',
				component: Welcome
			}, {
				path: '/main/personalCenter',
				name: 'PersonalCenter',
				component: PersonalCenter
			}, {
				path: '/main/roles',
				name: 'Roles',
				component: Roles
			}, {
				path: '/main/distributor',
				name: 'Distributor',
				component: Distributor
			}, {
				path: '/main/user',
				name: 'User',
				component: User
			}, {
				path: '/main/shopTable',
				name: 'ShopTable',
				component: ShopTable
			}, {
				path: '/main/goodsPropgroup',
				name: 'GoodsPropgroup',
				component: GoodsPropgroup
			}, {
				path: '/main/goodsProp',
				name: 'GoodsProp',
				component: GoodsProp
			}, {
				path: '/main/warehouse',
				name: 'Warehouse',
				component: Warehouse
			},
			{
				path: '/main/brand',
				name: 'Brand',
				component: Brand
			}, {
				path: '/main/goodsGeneral',
				name: 'GoodsGeneral',
				component: GoodsGeneral
			},
			{
				path: '/main/goodsSmall',
				name: 'GoodsSmall',
				component: GoodsSmall
			},
			{
				path: '/main/goodsSmaller',
				name: 'GoodsSmaller',
				component: GoodsSmaller
			}, {
				path: '/main/commodity',
				name: 'Commodity',
				component: Commodity
			}


		]

	}
]

const router = new VueRouter({
	routes
})

router.beforeEach((to, from, next) => {
	if (to.path == "/") {
		next();
	} else {
		let account = localStorage.getItem("com.woniu-account");
		if (account == undefined || account == null) {
			router.push("/");
		} else next();
	}

})
//这段代码是防止重复点击
const VueRouterPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(to) {
	return VueRouterPush.call(this, to).catch(err => err)
}

export default router
